/**
 * @ Author: luoqi
 * @ Create Time: 2024-03-14 10:01
 * @ Modified by: luoqi
 * @ Modified time: 2024-11-20 00:01
 * @ Description:
 */

#ifndef _LIST_H
#define _LIST_H

typedef struct _qlist {
    struct _qlist *prev;
    struct _qlist *next;
} QList;

#define QLIST_CREATE(name)              QList name = {&name, &name}

#define QLIST_ENTRY(ptr, type, member)    ((type *)((char *)(ptr) - ((unsigned long) &((type*)0)->member)))

#define QLIST_ITERATOR(node, list)      for (node = (list)->next; node != (list); node = node->next)

#define QLIST_ITERATOR_SAFE(node, cache, list)   for(node = (list)->next, cache = node->next; node != (list); node = cache, cache = node->next)

void qlist_init(QList* list);

void qlist_insert_after(QList* list, QList* node);

void qlist_insert_before(QList* list, QList* node);

void qlist_remove(QList* node);

int qlist_isempty(const QList* list);

int qlist_length(const QList* list);

int qlist_isexist(const QList* list, const QList* node);

#endif
